﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using PerformanceAssessment.Models;
using System.Data.Entity.ModelConfiguration.Conventions;

namespace PerformanceAssessment.Models
{
    public class PerformanceAssessmentDB : DbContext
    {
        public DbSet<AssessmentPeriod> AssessmentPeriods { get; set; }
        public DbSet<Assessment> Assessments { get; set; }
        public DbSet<Employee> Employees { get; set; }
        public DbSet<Goal> Goals { get; set; }
        public DbSet<Skill> Skills { get; set; }
        public DbSet<SkillAssessment> SkillAssessments { get; set; }
        public DbSet<Team> Teams { get; set; }
        public DbSet<SkillsPerTeam> SkillsPerTeam { get; set; }
        public DbSet<Manager> Managers { get; set; }
        public DbSet<Position> Positions { get; set; }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Entity<SkillsPerTeam>().ToTable("SkillsPerTeam");
            modelBuilder.Entity<AssessmentPeriod>()
                .HasMany(a => a.Teams)
                .WithMany(t => t.AssessmentPeriods)
                .Map(m => 
                { 
                    m.ToTable("TeamsPerAssessmentPeriod"); 
                    m.MapLeftKey("IdAssessmentPeriod"); 
                    m.MapRightKey("IdTeam");
                });
        }
    }
}